package cn.wolfcode.web.controller;

import cn.wolfcode.enums.CustomerReportEnum;
import cn.wolfcode.qo.CustomerReportQueryObject;
import cn.wolfcode.service.IBusinessService;
import cn.wolfcode.service.ICustomerReportService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/customerReport")
public class CustomerReportController {
    @Autowired
    private ICustomerReportService customerReportService;
    @Autowired
    private IBusinessService businessService;

    @RequestMapping("/list")
    public String customerReportList(@ModelAttribute("qo") CustomerReportQueryObject qo, Model model){
        //        枚举类共享
        model.addAttribute("items", CustomerReportEnum.values());
        PageInfo list= customerReportService.queryByName(qo);
        model.addAttribute("business",businessService.listAll());
        model.addAttribute("pageInfo",list);
        return "businessReport/list";
    }

    @RequestMapping("/echarts")
    public String Echarts(@ModelAttribute("qo") CustomerReportQueryObject qo, Model model){
//      柱状图不进行分页
        qo.setPageSize(0);
        PageInfo pageInfo = customerReportService.queryByName(qo);
        model.addAttribute("items",pageInfo.getList());
        return "businessReport/echarts";
    }
}
